﻿@inject IStringLocalizer<CascaderLabels> Localizer

<Divider Text="@Localizer["Divider1"]" Alignment="Alignment.Left" style="margin: 2rem 0;" />
<ValidateForm Model="@Model">
    <Cascader Color="Color.Primary" Items="@_items" @bind-Value="@Model.Address" />
</ValidateForm>
<Divider Text="@Localizer["Divider2"]" Alignment="Alignment.Left" style="margin: 2rem 0;" />
<Cascader Color="Color.Primary" Items="@_items" @bind-Value="@Model.Address" />
<Divider Text="@Localizer["Divider3"]" Alignment="Alignment.Left" style="margin: 2rem 0;" />
<Cascader Color="Color.Primary" Items="@_items" @bind-Value="@Model.Address" DisplayText="@Localizer["CascaderText"]" ShowLabel="true" />

@code {
    /// <summary>
    /// Foo 类为Demo测试用，如有需要请自行下载源码查阅
    /// Foo class is used for Demo test, please download the source code if necessary
    /// https://gitee.com/LongbowEnterprise/BootstrapBlazor/blob/main/src/BootstrapBlazor.Shared/Data/Foo.cs
    /// </summary>
    private Foo Model { get; set; } = new Foo();

    private List<CascaderItem> _items = new List<CascaderItem>();

    /// <summary>
    /// OnInitialized
    /// </summary>
    protected override void OnInitialized()
    {
        _items = new List<CascaderItem>
        {
            new CascaderItem(Localizer["item1"], Localizer["item1"]),
            new CascaderItem(Localizer["item2"], Localizer["item2"]),
            new CascaderItem(Localizer["item3"], Localizer["item3"]),
        };

        _items[0].AddItem(new CascaderItem("item1_child1", Localizer["item1_child1"]));
        _items[0].AddItem(new CascaderItem("item1_child2", Localizer["item1_child2"]));
        _items[0].AddItem(new CascaderItem("item1_child3", Localizer["item1_child3"]));
        _items[0].AddItem(new CascaderItem("item1_child4", Localizer["item1_child4"]));

        _items[0].Items.ElementAt(0).AddItem(new CascaderItem("item1_child1_child", Localizer["item1_child1_child"]));

        _items[1].AddItem(new CascaderItem("item2_child1", Localizer["item2_child1"]));
        _items[1].AddItem(new CascaderItem("item2_child2", Localizer["item2_child2"]));
        _items[1].AddItem(new CascaderItem("item2_child3", Localizer["item2_child3"]));

        _items[2].AddItem(new CascaderItem("item3_child1", Localizer["item3_child1"]));
        _items[2].AddItem(new CascaderItem("item3_child2", Localizer["item3_child2"]));
    }
}
